package com.qidi.hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 *  @ConditionalOnClass，当classpath下发现该类的情况下进行自动配置。
 *   @ConditionalOnMissingBean，当Spring Context中不存在该Bean时。
 *   @ConditionalOnProperty(prefix = "com.qidi.hello",value = "enabled",havingValue = "true")，当配置文件中com.qidi.hello.enabled=true时。
 *
 */
@Configuration
@ConditionalOnClass(HelloService.class)
@EnableConfigurationProperties(HelloServiceProperties.class)
public class HelloAutoConfigure {

    @Autowired
    private HelloServiceProperties properties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "com.qidi.hello",value = "enabled",havingValue = "true")
    HelloService helloService (){

        return  new HelloService(properties.getPrefix(),properties.getSuffix());
    }

}
